﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for clsProductsRecord
/// </summary>
public class clsProductsRecord
{
    #region MEMBER VARIABLES

        private int m_iProductID;
        private DateTime m_dtAdded;
        private int m_iAddedBy;
        private DateTime m_dtEdited;
        private int m_iEditedBy;
        private string m_strProductName;
        private string m_strProductShortDesc;
        private string m_strProductFullDesc;
        private Double m_dblPrice;
        private string m_strPicture;
        private int m_iProductCategory;
        private int m_iViewed;
        private int m_iInStock;
        private bool m_bIsActive;
        protected clsUser m_clsUser; 
    
    #endregion

    #region PROPERTIES

        public int iProductID
    {
        get
        {
            return m_iProductID;
        }
    }

    public DateTime dtAdded
    {
        get
        {
            return m_dtAdded;
        }
        set
        {
            m_dtAdded = value;
        }
    }

    public int iAddedBy
    {
        get
        {
            return m_iAddedBy;
        }
        set
        {
            m_iAddedBy = value;
        }
    }

    public DateTime dtEdited
    {
        get
        {
            return m_dtEdited;
        }
        set
        {
            m_dtEdited = value;
        }
    }

    public int iEditedBy
    {
        get
        {
            return m_iEditedBy;
        }
        set
        {
            m_iEditedBy = value;
        }
    }

    public String strProductName
    {
        get
        {
            return m_strProductName;
        }
        set
        {
            m_strProductName = value;
        }
    }

    public String strProductShortDesc
    {
        get
        {
            return m_strProductShortDesc;
        }
        set
        {
            m_strProductShortDesc = value;
        }
    }

    public String strProductFullDesc
    {
        get
        {
            return m_strProductFullDesc;
        }
        set
        {
            m_strProductFullDesc = value;
        }
    }

    public Double dblPrice
    {
        get
        {
            return m_dblPrice;
        }
        set
        {
            m_dblPrice = value;
        }
    }

    public String strPicture
    {
        get
        {
            return m_strPicture;
        }
        set
        {
            m_strPicture = value;
        }
    }

    public int iProductCategory
    {
        get
        {
            return m_iProductCategory;
        }
        set
        {
            m_iProductCategory = value;
        }
    }

    public int iViewed
    {
        get
        {
            return m_iViewed;
        }
        set
        {
            m_iViewed = value;
        }
    }

    public int iInStock
    {
        get
        {
            return m_iInStock;
        }
        set
        {
            m_iInStock = value;
        }
    }

    public bool bIsActive
    {
        get
        {
            return m_bIsActive;
        }
        set
        {
            m_bIsActive = value;
        }
    }

    #endregion

    #region CONSTRUCTORS

    public clsProductsRecord(clsUser clsUser)
    {
        m_clsUser = clsUser;
        m_iProductID = 0;
    }

    public clsProductsRecord(clsUser clsUser, int iProductID) : this(clsUser)
    {
        m_iProductID = iProductID;
        GetData();
    }

    #endregion

    #region PUBLIC METHODS

    public virtual void Update()
    {
        try
        {
            clsCommonFunctions clsCommonFunctions = new clsCommonFunctions();
            if (iProductID == 0)
            {
                //### Add
                m_iProductID = (int)DataConnection.GetDataObject().ExecuteScalar("spProductsInsert '" +
                    this.m_dtAdded + "'," + this.m_iAddedBy + " ,'" + this.m_dtEdited + "', " + this.m_iEditedBy + 
                    ", '" + clsCommonFunctions.escapeChar(this.m_strProductName) + 
                    "', '" + clsCommonFunctions.escapeChar(this.m_strProductShortDesc) +
                    "', '" + clsCommonFunctions.escapeChar(this.m_strProductFullDesc) + 
                    "',  '" + this.m_dblPrice + 
                    "',  '" + clsCommonFunctions.escapeChar(this.m_strPicture)  +
                    "',  '" + this.m_iProductCategory +
                    "',  '" + this.m_iViewed +
                    "',  '" + this.m_iInStock + "'");
            }
            else
            {
                //### Update
                DataConnection.GetDataObject().Execute("spProductsUpdate " + this.m_iProductID +
                    ", '" + clsCommonFunctions.escapeChar(this.m_strProductName) +
                    "', '" + clsCommonFunctions.escapeChar(this.m_strProductShortDesc) +
                    "', '" + clsCommonFunctions.escapeChar(this.m_strProductFullDesc) +
                    "',  '" + this.m_dblPrice +
                    "',  '" + clsCommonFunctions.escapeChar(this.m_strPicture) +
                    "',  '" + this.m_iProductCategory +
                    "',  '" + this.m_iViewed +
                    "',  '" + this.m_iInStock + "'");
            }
        }
        catch (Exception ex)
        {
            clsErrorLog.LogError(ex, this, m_clsUser, 95);
            throw ex;
        }
    }

    public virtual void Delete()
    {
        DataConnection.GetDataObject().Execute("spProductCategoryDelete " + this.m_iProductID);
    }

    #endregion

    #region PROTECTED METHODS

    protected virtual void GetData()
    {
        try
        {
            DataSet dtsData;
            dtsData = new DataSet();
            dtsData = DataConnection.GetDataObject().GetData("Data", "spProductCategoryGetRecord " + this.m_iProductID);
            m_dtAdded = Convert.ToDateTime(dtsData.Tables["Data"].Rows[0]["dtAdded"]);
            m_iAddedBy = Convert.ToInt32(dtsData.Tables["Data"].Rows[0]["iAddedBy"]);
            m_dtEdited = Convert.ToDateTime(dtsData.Tables["Data"].Rows[0]["dtEdited"]);
            m_iEditedBy = Convert.ToInt32(dtsData.Tables["Data"].Rows[0]["iEditedBy"]);
            //m_strProductTitle = dtsData.Tables["Data"].Rows[0]["strProductTitle"].ToString();
            //m_strShortDescription = dtsData.Tables["Data"].Rows[0]["strShortDescription"].ToString();
            //m_strFullDescription = dtsData.Tables["Data"].Rows[0]["strFullDescription"].ToString();
            //m_strDubblePrice = dtsData.Tables["Data"].Rows[0]["strDubblePrice"].ToString();
            //m_strPathToImage = dtsData.Tables["Data"].Rows[0]["strPathToImage"].ToString();
            //m_bIsActive = Convert.ToBoolean(dtsData.Tables["Data"].Rows[0]["bIsActive"]);

        }
        catch (Exception ex)
        {
            clsErrorLog.LogError(ex, this, m_clsUser, 95);
            throw ex;
        }
    }

    #endregion
}
